package com.luxoft.scoremanager.server.model.entity;

import com.luxoft.scoremanager.server.model.bean.ComponentBean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.io.Serializable;

@Entity
@Table
public class ComponentValue implements Serializable {
    private static final long serialVersionUID = -5170875020617735666L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "my_entity_seq_gen")
    @SequenceGenerator(name = "my_entity_seq_gen", sequenceName = "CVD_SEQ")
    @Column(name = "component_Value_id")
    private Integer id;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "component_ID")
    private Component component;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "score_Package_ID")
    private ScorePackage scorePackage;

    @Column
    private String existsValue;

    @Column
    private String finalValue;

    @Override
    public String toString() {
        return "ComponentValue{" +
                "id=" + id +
                ", component=" + component +
                ", scorePackage=" + scorePackage +
                ", existsValue='" + existsValue + '\'' +
                ", finalValue='" + finalValue + '\'' +
                '}';
    }

    public ComponentValue() {
    }

    public ComponentValue(ComponentBean componentBean) {
        this.setFinalValue(componentBean.getFinalValue());
        this.setExistsValue(componentBean.getExistsValue());
        this.setComponent(new Component(componentBean.getId(), componentBean.getLabel(), componentBean.getStaticData()));
        this.setId(componentBean.getComponentValueId());
    }

    public ComponentValue(String existsValue, String finalValue) {
        this.existsValue = existsValue;
        this.finalValue = finalValue;
    }

    @Deprecated
    public ComponentValue(Integer id, String existsValue, String finalValue) {
        this.id = id;
        this.existsValue = existsValue;
        this.finalValue = finalValue;
    }

    public ComponentValue(String existsValue, String finalValue, Component component, ScorePackage scorePackage) {
        this.existsValue = existsValue;
        this.finalValue = finalValue;
        this.scorePackage = scorePackage;
        this.component = component;
    }

    @Override
    public boolean equals(Object o) {

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ComponentValue that = (ComponentValue) o;

        if (!id.equals(that.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    public Integer getId() {

        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Component getComponent() {
        return component;
    }

    public void setComponent(Component component) {
        this.component = component;
    }

    public ScorePackage getScorePackage() {
        return scorePackage;
    }

    public void setScorePackage(ScorePackage scorePackage) {
        this.scorePackage = scorePackage;
    }

    public String getExistsValue() {
        return existsValue;
    }

    public void setExistsValue(String existsValue) {
        this.existsValue = existsValue;
    }

    public String getFinalValue() {
        return finalValue;
    }

    public void setFinalValue(String finalValue) {
        this.finalValue = finalValue;
    }


}
